package cn.hx.mall.order.controller;

import cn.hx.mall.order.entity.Order;
import cn.hx.mall.order.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 订单列表控制层
 *
 * @author NetherSo
 * @since 2022-11-10
 **/
@Controller
@RequestMapping("order")
public class OrderListController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    /**
     * 根据条件搜索
     *
     * @param order 查询的订单条件
     */
    @GetMapping("orderList")
    public String orderList(Order order, Map<String, Object> attr, PageInfo pageInfo) {
        if (pageInfo.getPageNum() == 0) {
            pageInfo.setPageNum(1);
        }
        if (pageInfo.getPageSize() == 0) {
            pageInfo.setPageSize(10);
        }
        PageHelper.startPage(pageInfo);

        //填装orderList数据
        List<Order> orders = orderService.queryAll(order);
        PageInfo<Order> orderPageInfo = new PageInfo<>(orders);
        attr.put("orderList", orders);
        attr.put("pageInfo", orderPageInfo);

        return "order/orderList";
    }
}
